package cmd

import (
	"git.julive.com/julive/user/server"
	"github.com/spf13/cobra"
	"log"
)

var serverCmd = &cobra.Command{
	Use:   "server",
	Short: "Run the gRPC User server",
	Run: func(cmd *cobra.Command, args []string) {
		defer func() {
			if err := recover(); err != nil {
				log.Printf("Recover error : %v\n", err)
			}
		}()
		err := server.Serve()
		if err != nil {
			panic(err)
		}
	},
}

func init() {
	serverCmd.Flags().IntVarP(&server.GRPCPort, "grpc-port", "g", 8081, "grpc port")
	serverCmd.Flags().IntVarP(&server.HTTPPort, "http-port", "p", 8080, "http port")
	rootCmd.AddCommand(serverCmd)
}
